$(function () {
	select1();
	$('#S1').bind("change", select2);
	$('#S2').bind("change", select3);
	});

function select1() {
	$.ajax(
	{
	    type: "post",
	    url: "/JJR/html/lib/address.php",
	    data: {"type":1},
	    success: function (msg) {
	    	msg = $.parseJSON(msg);
	    	$("#S1").append("<option value="  + "0>" + "</option>");
	        for (var i = 0; i < msg.length; i++) {
	            $("#S1").append("<option value='" +msg[i].provinceId+ "'>" + msg[i].province + "</option>");
	        }
	        select2();
	        
	    }
	})
};


function select2() {
	$("#S2").html("");
	$.ajax(
	{
	    type: "post",
	    url: "/JJR/html/lib/address.php",
	    data: {"add_code":$('#S1').val(),"type":2},
	    success: function (msg) {
		    //alert($('#S1').val());
	    	msg = $.parseJSON(msg);
	    	$("#S2").append("<option value="  + "0>" + "</option>");
	        for (var i = 0; i < msg.length; i++) {
	            $("#S2").append("<option value=" + msg[i].cityId + ">" + msg[i].city + "</option>");
	        }
	        select3();
	    }
	})
};

function select3() {
	$("#S3").html("");
	$.ajax(
	{
	    type: "post",
	    url: "/JJR/html/lib/address.php",
	    data: { "add_code":$('#S2').val(),"type":3},
	    success: function (msg) {
	    	msg = $.parseJSON(msg);
	    	$("#S3").append("<option value="  + "0>" + "</option>");
	        for (var i = 0; i < msg.length; i++) {
	            $("#S3").append("<option value=" + msg[i].areaId + ">" + msg[i].area+ "</option>");
	        }
	       // $("#myadd").val($("#S1 option:selected").text()+"|"+$("#S2 option:selected").text()+"|"+$("#S3 option:selected").text());
	       // $("#myaddcode").val($("#S1").val()+"|"+$("#S2").val()+"|"+$("#S3").val());
	    }
	})
};

function check_name(){   //check name
	 $.ajax({ url:"/JJR/html/lib/check.php",
	 		data:{'check_str':$("#name").val(),'type':1}, 
	 		type:'post',
	        success: function(obj){
	        	obj = $.parseJSON(obj);
	        	if(obj.state<1){	//出现错误
	   			 	alert(obj.tip);
	        		$("#nameImg").removeClass().addClass("glyphicon glyphicon-exclamation-sign");
	   			 }
	   			else{
	                $("#nameImg").removeClass().addClass("glyphicon glyphicon-ok-sign");
	   			}				 
	}});   
}    


function check_phone(){   //check name
	 $.ajax({ url:"/JJR/html/lib/check.php",
	 		data:{'check_str':$("#phone").val(),'type':2}, 
	 		type:'post',
	        success: function(obj){
	        	obj = $.parseJSON(obj);
	        	if(obj.state<1){	//出现错误
	   			 	alert(obj.tip);
	        		$("#phoneImg").removeClass().addClass("glyphicon glyphicon-remove-sign");
	   			 }
	   			else{
	                $("#phoneImg").removeClass().addClass("glyphicon glyphicon-ok-sign");
	   			}				 
	}});   
}

var _str = "<div id='test' class='input-group'> <div class='input-group-addon'><span class='glyphicon glyphicon-earphone' aria-hidden='true'></span></div> <input name='phone' type='text' class='form-control' id='phone' placeholder='电话' onChange='check_phone()' > <div class='input-group-addon'> <span id='phoneImg' class='' aria-hidden='true'></span> <span  id='phoneImg' class='glyphicon glyphicon-minus-sign' aria-hidden='true' onClick='removePhone()' ></span>   </div> </div>";


function removePhone(){
	$("#test").remove();
}


function addPhone(){
	alert("add phone");
	$("#phone-split").before(_str);
}
    

function test(){
    
    document.form1.submit();
}
    
    
$(function() {
	var ms_1 = $('#ms-scrabble-1').magicSuggest({
		placeholder: '欲购买设备类型',
        value:['挖掘机','其他'],
		data: ['挖掘机', '装载机', '其他']
        
	});

		var ms_2 = $('#ms-scrabble-2').magicSuggest({
			placeholder: '挖掘机品牌',
			data: ['卡特', '小松', '日立', '斗山', '现代', '沃尔沃', '神钢', '其他']
		});

			var ms_2 = $('#ms-scrabble-3').magicSuggest({
				placeholder: '装载机品牌',
				data: ['柳工', '临工', '成工', '龙工', '厦工', '山工',  '其他']
			});

				/* 取数据
				 $(ms_1).on('selectionchange', function(){
				 //alert(JSON.stringify(this.getSelection()));
				 alert(this.getSelection());
				 });
				 */

});